package cn.itsource.org.controller;

import cn.itsource.basic.util.AxajResult;
import cn.itsource.basic.util.PageInfo;
import cn.itsource.org.domain.Shop;
import cn.itsource.org.domain.Employee;
import cn.itsource.org.query.ShopQuery;
import cn.itsource.org.service.IShopService;
import cn.itsource.org.service.IEmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//商家入驻controller层
@RestController
@RequestMapping("/shop")
@Api(tags = "商家入驻接口",description = "商家入驻接口详细描述")
public class ShopController {
    @Autowired
    private IShopService shopService;
    /**
     *
     * @param shop   有ID是修改，没得是保存
     * @return          @RequestBody：前端传入的数据时json必须加此注解
     */
    @PostMapping
    @ApiOperation(value = "商家入驻添加或修改",notes = "如果有id就是修改否则就是添加")
    public AxajResult save(@RequestBody Shop shop) {
        try {
            shopService.save(shop);
            return new AxajResult();
        } catch (Exception e) {
            return new AxajResult(false,e.getMessage());
        }
    }
    /**
     *
     * @param id    通过id删除
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "商家入驻删除",notes = "很好用的接口")
    public AxajResult delete(@PathVariable("id")Long id) {
        try {
            shopService.delete(id);
            return new AxajResult();
        } catch (Exception e) {
            return new AxajResult(false,e.getMessage());
        }
    }



    /**
     * 查询所有的商家入驻对象
     * @return
     */
    @PatchMapping
    @ApiOperation(value = "查询所有商家入驻",notes = "很好用的接口")
    public PageInfo<Shop> findAll(@RequestBody ShopQuery shopQuery){
        //分页查询
        return  shopService.findAllByQuery(shopQuery);
    }

    /**
     * 商家入驻
     * @param shop  店铺信息
     * @return
     */
    @PostMapping("/settlement")
    @ApiOperation(value = "商家入驻",notes = "很好用的接口")
    public AxajResult settlement(@RequestBody Shop shop){
        try {
            //商家入驻
            shopService.settlement(shop);
            return new AxajResult();
        } catch (Exception e) {
            e.printStackTrace();
            return  new AxajResult(false,e.getMessage());
        }
    }
    /**
     *
     * @param id    通过id删除
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "通过id查询商家",notes = "很好用的接口")
    public Shop findById(@PathVariable("id")Long id) {
        return shopService.findById(id);
    }
}
